using System.ComponentModel.DataAnnotations;

namespace Lzfy_His_Service.Models
{
    /// <summary>
    /// 企业微信OAuth2.0授权请求
    /// </summary>
    public class WeChatWorkAuthRequest
    {
        /// <summary>
        /// 授权码
        /// </summary>
        [Required(ErrorMessage = "授权码不能为空")]
        public string Code { get; set; } = string.Empty;

        /// <summary>
        /// 状态参数
        /// </summary>
        public string? State { get; set; }
    }

    /// <summary>
    /// 企业微信用户信息
    /// </summary>
    public class WeChatWorkUserInfo
    {
        /// <summary>
        /// 用户ID
        /// </summary>
        public string UserId { get; set; } = string.Empty;

        /// <summary>
        /// 用户姓名
        /// </summary>
        public string Name { get; set; } = string.Empty;

        /// <summary>
        /// 部门ID列表
        /// </summary>
        public int[] Department { get; set; } = Array.Empty<int>();

        /// <summary>
        /// 职位
        /// </summary>
        public string Position { get; set; } = string.Empty;

        /// <summary>
        /// 手机号
        /// </summary>
        public string Mobile { get; set; } = string.Empty;

        /// <summary>
        /// 邮箱
        /// </summary>
        public string Email { get; set; } = string.Empty;

        /// <summary>
        /// 头像URL
        /// </summary>
        public string Avatar { get; set; } = string.Empty;

        /// <summary>
        /// 性别
        /// </summary>
        public string Gender { get; set; } = string.Empty;

        /// <summary>
        /// 状态
        /// </summary>
        public int Status { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public int Enable { get; set; }
    }

    /// <summary>
    /// 企业微信登录响应
    /// </summary>
    public class WeChatWorkLoginResponse
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }

        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; } = string.Empty;

        /// <summary>
        /// JWT Token
        /// </summary>
        public string? Token { get; set; }

        /// <summary>
        /// 用户信息
        /// </summary>
        public WeChatWorkUserInfo? UserInfo { get; set; }

        /// <summary>
        /// 过期时间
        /// </summary>
        public DateTime? ExpiresAt { get; set; }
    }

    /// <summary>
    /// 企业微信授权URL请求
    /// </summary>
    public class WeChatWorkAuthUrlRequest
    {
        /// <summary>
        /// 回调URL
        /// </summary>
        public string? RedirectUri { get; set; }

        /// <summary>
        /// 状态参数
        /// </summary>
        public string? State { get; set; }
    }

    /// <summary>
    /// 企业微信授权URL响应
    /// </summary>
    public class WeChatWorkAuthUrlResponse
    {
        /// <summary>
        /// 授权URL
        /// </summary>
        public string AuthUrl { get; set; } = string.Empty;

        /// <summary>
        /// 状态参数
        /// </summary>
        public string State { get; set; } = string.Empty;
    }

    /// <summary>
    /// 企业微信配置
    /// </summary>
    public class WeChatWorkConfig
    {
        /// <summary>
        /// 企业ID
        /// </summary>
        public string CorpId { get; set; } = string.Empty;

        /// <summary>
        /// 应用Secret
        /// </summary>
        public string CorpSecret { get; set; } = string.Empty;

        /// <summary>
        /// 应用ID
        /// </summary>
        public string AgentId { get; set; } = string.Empty;

        /// <summary>
        /// 回调域名
        /// </summary>
        public string CallbackDomain { get; set; } = string.Empty;

        /// <summary>
        /// 前端成功跳转URL
        /// </summary>
        public string FrontendSuccessUrl { get; set; } = string.Empty;

        /// <summary>
        /// 前端错误跳转URL
        /// </summary>
        public string FrontendErrorUrl { get; set; } = string.Empty;
    }

    /// <summary>
    /// 通过企业微信用户ID查询用户名请求
    /// </summary>
    public class WeChatWorkUsernameRequest
    {
        /// <summary>
        /// 企业微信用户ID
        /// </summary>
        [Required(ErrorMessage = "企业微信用户ID不能为空")]
        public string WxUserId { get; set; } = string.Empty;
    }

    /// <summary>
    /// 通过企业微信用户ID查询用户名响应
    /// </summary>
    public class WeChatWorkUsernameResponse
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }

        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; } = string.Empty;

        /// <summary>
        /// 用户名
        /// </summary>
        public string? Username { get; set; }

        /// <summary>
        /// 用户全名
        /// </summary>
        public string? FullName { get; set; }

        /// <summary>
        /// 手机号
        /// </summary>
        public string? Mobile { get; set; }

        /// <summary>
        /// 职位
        /// </summary>
        public string? Position { get; set; }

        /// <summary>
        /// 主要部门
        /// </summary>
        public string? MainDeps { get; set; }
    }

    /// <summary>
    /// 企业微信用户详细信息请求
    /// </summary>
    public class WeChatWorkUserDetailRequest
    {
        /// <summary>
        /// 用户名
        /// </summary>
        [Required(ErrorMessage = "用户名不能为空")]
        public string Username { get; set; } = string.Empty;
    }

    /// <summary>
    /// 企业微信用户详细信息响应
    /// </summary>
    public class WeChatWorkUserDetailResponse
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }

        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; } = string.Empty;

        /// <summary>
        /// 用户ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        public string? Username { get; set; }

        /// <summary>
        /// 用户全名
        /// </summary>
        public string? FullName { get; set; }

        /// <summary>
        /// 用户角色
        /// </summary>
        public string Role { get; set; } = "User";

        /// <summary>
        /// 用户电话
        /// </summary>
        public string? UserPhone { get; set; }

        /// <summary>
        /// JWT Token
        /// </summary>
        public string? Token { get; set; }

        /// <summary>
        /// 过期时间
        /// </summary>
        public DateTime? ExpiresAt { get; set; }
    }

    /// <summary>
    /// 企业微信消息推送请求
    /// </summary>
    public class WeChatWorkMessageRequest
    {
        /// <summary>
        /// 用户ID（企业微信用户ID或系统用户ID）
        /// </summary>
        [Required(ErrorMessage = "用户ID不能为空")]
        public string UserId { get; set; } = string.Empty;

        /// <summary>
        /// 消息内容
        /// </summary>
        [Required(ErrorMessage = "消息内容不能为空")]
        public string Content { get; set; } = string.Empty;

        /// <summary>
        /// 消息类型（text: 文本消息, textcard: 文本卡片消息, markdown: markdown消息）
        /// </summary>
        public string MessageType { get; set; } = "text";

        /// <summary>
        /// 消息标题（仅文本卡片消息使用）
        /// </summary>
        public string? Title { get; set; }

        /// <summary>
        /// 消息描述（仅文本卡片消息使用）
        /// </summary>
        public string? Description { get; set; }

        /// <summary>
        /// 跳转链接（仅文本卡片消息使用）
        /// </summary>
        public string? Url { get; set; }

        /// <summary>
        /// 按钮文字（仅文本卡片消息使用）
        /// </summary>
        public string? BtnTxt { get; set; }
    }

    /// <summary>
    /// 企业微信消息推送响应
    /// </summary>
    public class WeChatWorkMessageResponse
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }

        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; } = string.Empty;

        /// <summary>
        /// 企业微信API返回的错误码
        /// </summary>
        public int? ErrorCode { get; set; }

        /// <summary>
        /// 企业微信API返回的错误信息
        /// </summary>
        public string? ErrorMessage { get; set; }

        /// <summary>
        /// 消息ID（发送成功时返回）
        /// </summary>
        public string? MessageId { get; set; }
    }

    /// <summary>
    /// 企业微信文本消息
    /// </summary>
    public class WeChatWorkTextMessage
    {
        /// <summary>
        /// 接收消息的用户ID
        /// </summary>
        public string touser { get; set; } = string.Empty;

        /// <summary>
        /// 消息类型
        /// </summary>
        public string msgtype { get; set; } = "text";

        /// <summary>
        /// 应用ID
        /// </summary>
        public string agentid { get; set; } = string.Empty;

        /// <summary>
        /// 文本消息内容
        /// </summary>
        public WeChatWorkTextContent text { get; set; } = new();

        /// <summary>
        /// 是否保密消息
        /// </summary>
        public int safe { get; set; } = 0;
    }

    /// <summary>
    /// 企业微信文本消息内容
    /// </summary>
    public class WeChatWorkTextContent
    {
        /// <summary>
        /// 消息内容
        /// </summary>
        public string content { get; set; } = string.Empty;
    }

    /// <summary>
    /// 企业微信文本卡片消息
    /// </summary>
    public class WeChatWorkTextCardMessage
    {
        /// <summary>
        /// 接收消息的用户ID
        /// </summary>
        public string touser { get; set; } = string.Empty;

        /// <summary>
        /// 消息类型
        /// </summary>
        public string msgtype { get; set; } = "textcard";

        /// <summary>
        /// 应用ID
        /// </summary>
        public string agentid { get; set; } = string.Empty;

        /// <summary>
        /// 文本卡片消息内容
        /// </summary>
        public WeChatWorkTextCardContent textcard { get; set; } = new();

        /// <summary>
        /// 是否保密消息
        /// </summary>
        public int safe { get; set; } = 0;
    }

    /// <summary>
    /// 企业微信文本卡片消息内容
    /// </summary>
    public class WeChatWorkTextCardContent
    {
        /// <summary>
        /// 标题
        /// </summary>
        public string title { get; set; } = string.Empty;

        /// <summary>
        /// 描述
        /// </summary>
        public string description { get; set; } = string.Empty;

        /// <summary>
        /// 跳转链接
        /// </summary>
        public string url { get; set; } = string.Empty;

        /// <summary>
        /// 按钮文字
        /// </summary>
        public string btntxt { get; set; } = "详情";
    }

    /// <summary>
    /// 企业微信Markdown消息
    /// </summary>
    public class WeChatWorkMarkdownMessage
    {
        /// <summary>
        /// 接收消息的用户ID
        /// </summary>
        public string touser { get; set; } = string.Empty;

        /// <summary>
        /// 消息类型
        /// </summary>
        public string msgtype { get; set; } = "markdown";

        /// <summary>
        /// 应用ID
        /// </summary>
        public string agentid { get; set; } = string.Empty;

        /// <summary>
        /// Markdown消息内容
        /// </summary>
        public WeChatWorkMarkdownContent markdown { get; set; } = new();

        /// <summary>
        /// 是否保密消息
        /// </summary>
        public int safe { get; set; } = 0;
    }

    /// <summary>
    /// 企业微信Markdown消息内容
    /// </summary>
    public class WeChatWorkMarkdownContent
    {
        /// <summary>
        /// Markdown内容
        /// </summary>
        public string content { get; set; } = string.Empty;
    }

    /// <summary>
    /// 企业微信API响应基类
    /// </summary>
    public class WeChatWorkApiResponse
    {
        /// <summary>
        /// 错误码
        /// </summary>
        public int errcode { get; set; }

        /// <summary>
        /// 错误信息
        /// </summary>
        public string errmsg { get; set; } = string.Empty;
    }

    /// <summary>
    /// 企业微信发送消息API响应
    /// </summary>
    public class WeChatWorkSendMessageApiResponse : WeChatWorkApiResponse
    {
        /// <summary>
        /// 消息ID
        /// </summary>
        public string? msgid { get; set; }

        /// <summary>
        /// 不合法的用户ID列表
        /// </summary>
        public string? invaliduser { get; set; }

        /// <summary>
        /// 不合法的部门ID列表
        /// </summary>
        public string? invalidparty { get; set; }

        /// <summary>
        /// 不合法的标签ID列表
        /// </summary>
        public string? invalidtag { get; set; }
    }

    /// <summary>
    /// 企业微信Access Token响应
    /// </summary>
    public class WeChatWorkAccessTokenResponse : WeChatWorkApiResponse
    {
        /// <summary>
        /// Access Token
        /// </summary>
        public string? access_token { get; set; }

        /// <summary>
        /// 过期时间（秒）
        /// </summary>
        public int expires_in { get; set; }
    }
}